<?
include('base.php');
User::protect();
$section = 'admin_streaming_audio';
include_class('config');

$conf = new Config();

if ($_GET['task'] == 'update') {
	$args = array("streamingAudioFilesPath", "streamingAudioServerURL");
	$r1 = $conf->update('streamingAudioFilesPath', $_POST['streamingAudioFilesPath']);
	$r2 = $conf->update('streamingAudioServerURL', $_POST['streamingAudioServerURL']);
	$er = new Error();
	if (db::isError($r1)) {
		$er->add($r1);
	}
	if (db::isError($r2)) {
		$er->add($r2);
	}
	if (!$er->hasErrors()) {
		header('Location: admin_streaming_audio.php');
		exit;
	}
}
$page_title = 'Streaming Audio Setup';
include('layout/header.php');

?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="admin.php">Administer Audition&nbsp;&#62;</a>&nbsp;Streaming Audio Setup
</div>
<?

$u = User::getCurrent();
if (!$u->isAdmin()) { 
	Error::outputDialog('Return to Main Menu', 'index.php', 'Only an administrator may access administrator options.');
} else { 

	if (db::isError($er)) {
		$er->outputList();
	}

if (($_GET['task'] == 'edit' || $_GET['task'] == 'update') && User::isAdmin()) { 

	$streamingAudioFilesPath = ($_POST) ? $_POST['streamingAudioFilesPath'] : $conf->getSetting('streamingAudioFilesPath');
	$streamingAudioServerURL = ($_POST) ? $_POST['streamingAudioServerURL'] : $conf->getSetting('streamingAudioServerURL');

?>
	
	<h1>edit streaming audio information:</h1>
	<div class="inset">
	<form id="edit_entry" action="<?=$PHP_SELF?>?task=update" method="post">
	<div class="edit-form">
	<strong>Path to Files</strong><br/>Note: This path must be writeable by the web server. Audio files configured for streaming will be placed in this location. <strong>Do not include a trailing slash on the directory path.</strong><br/>
	<input type="text" class="text" name="streamingAudioFilesPath" value="<?=$streamingAudioFilesPath?>" />
	</div>
	<div class="edit-form">
	<strong>Shoutcast Audio Server</strong><br/>(e.g.: http://www.your-site.com:8000/content). This is the server prefix to any files that will be downloaded. <strong>Do not include a trailing slash on the URL.</strong><br/>
	<input type="text" class="text" name="streamingAudioServerURL" value="<?=$streamingAudioServerURL?>" />
	</div>
	
	<input type="submit" value="Update Settings" class="button" name="submit">
	<input type="submit" value="Exit Without Updating" class="button" name="preview" onclick="location.href='band_information.php'; return false">
	</form>
	</div>
	

<? } else { ?>

	<h1>view streaming audio information:</h1>
	<div class="inset">
		<h2>Path to Files</h2>
		<?= $conf->getSetting('streamingAudioFilesPath'); ?>
		<br/><br/>
		
		<h2>Streaming Audio Server</h2>
		<?= $conf->getSetting('streamingAudioServerURL'); ?>
		<br/><br/>
	
		<form name="entry_status" method="get">
			<input type="submit" name="" value="Edit Information" onclick="location.href='<?=$PHP_SELF?>?task=edit';return false" class="button">
			<input type="button" value="Return to Administration Menu" name="" onclick="location.href='admin.php'; return false" class="button">
		</form>
		
	</div>

<? } 

}?>

<? include('layout/footer.php'); ?>
